from typing import Union

from fastapi import FastAPI,Request,status

from starlette.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/")
def read_root():
    return {"Hello": "hanleng"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}


@app.put("/items/{item_id}",status_code = status.HTTP_200_OK)
async def update_item(item_id:int,request:Request):
    data = await request.json()
    return {"item_name": data['name'], "item_id": item_id}

def get_full_name(first_name:str,last_name:str):
  full_name = first_name.title() +last_name.title()
  return full_name



print(get_full_name('han','leng'))
# # 启动FastAPI应用
# if __name__ == "__main__":
#     import uvicorn

#     uvicorn.run(app, host="0.0.0.0", port=8000)
